Special:Log and the logging table -- unified logging scariness!
[lhc/web/wiklou.git] / includes / SpecialIpblocklist.php
1 <?php
2
3 function wfSpecialIpblocklist()
4 {
5 global $wgUser, $wgOut, $wgRequest;
6
7 $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
8 $reason = $wgRequest->getText( 'wpUnblockReason' );
9 $action = $wgRequest->getText( 'action' );
10
11 $ipu = new IPUnblockForm( $ip, $reason );
12
13 if ( "success" == $action ) {
14 $msg = wfMsg( "ipusuccess", $ip );
15 $ipu->showList( $msg );
16 } else if ( "submit" == $action && $wgRequest->wasPosted() ) {
17 if ( ! $wgUser->isSysop() ) {
18 $wgOut->sysopRequired();
19 return;
20 }
21 $ipu->doSubmit();
22 } else if ( "unblock" == $action ) {
23 $ipu->showForm( "" );
24 } else {
25 $ipu->showList( "" );
26 }
27 }
28
29 class IPUnblockForm {
30 var $ip, $reason;
31
32 function IPUnblockForm( $ip, $reason ) {
33 $this->ip = $ip;
34 $this->reason = $reason;
35 }
36
37 function showForm( $err )
38 {
39 global $wgOut, $wgUser, $wgLang;
40
41 $wgOut->setPagetitle( wfMsg( "unblockip" ) );
42 $wgOut->addWikiText( wfMsg( "unblockiptext" ) );
43
44 $ipa = wfMsg( "ipaddress" );
45 $ipr = wfMsg( "ipbreason" );
46 $ipus = htmlspecialchars( wfMsg( "ipusubmit" ) );
47 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
48 $action = $titleObj->escapeLocalURL( "action=submit" );
49
50 if ( "" != $err ) {
51 $wgOut->setSubtitle( wfMsg( "formerror" ) );
52 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
53 }
54
55 $wgOut->addHTML( "
56 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
57 <table border='0'>
58 <tr>
59 <td align='right'>{$ipa}:</td>
60 <td align='left'>
61 <input tabindex='1' type='text' size='20' name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip ) . "\" />
62 </td>
63 </tr>
64 <tr>
65 <td align='right'>{$ipr}:</td>
66 <td align='left'>
67 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason ) . "\" />
68 </td>
69 </tr>
70 <tr>
71 <td>&nbsp;</td>
72 <td align='left'>
73 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
74 </td>
75 </tr>
76 </table>
77 </form>\n" );
78
79 }
80
81 function doSubmit()
82 {
83 global $wgOut, $wgUser, $wgLang;
84
85 $block = new Block();
86 $this->ip = trim( $this->ip );
87
88 if ( $this->ip{0} == "#" ) {
89 $block->mId = substr( $this->ip, 1 );
90 } else {
91 $block->mAddress = $this->ip;
92 }
93
94 # Delete block (if it exists)
95 # We should probably check for errors rather than just declaring success
96 $block->delete();
97
98 # Make log entry
99 $log = new LogPage( 'block' );
100 $log->addEntry( 'unblock', Title::makeTitle( NS_USER, $this->ip ), $this->reason );
101
102 # Report to the user
103 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
104 $success = $titleObj->getFullURL( "action=success&ip=" . urlencode( $this->ip ) );
105 $wgOut->redirect( $success );
106 }
107
108 function showList( $msg )
109 {
110 global $wgOut;
111
112 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
113 if ( "" != $msg ) {
114 $wgOut->setSubtitle( $msg );
115 }
116 $wgOut->addHTML( "<ul>" );
117 Block::enumBlocks( "wfAddRow", 0 );
118 $wgOut->addHTML( "</ul>\n" );
119 }
120 }
121
122 # Callback function to output a block
123 function wfAddRow( $block, $tag ) {
124 global $wgOut, $wgUser, $wgLang;
125
126 $sk = $wgUser->getSkin();
127
128 # Hide addresses blocked by User::spreadBlocks, for privacy
129 $addr = $block->mAuto ? "#{$block->mId}" : $block->mAddress;
130
131 $name = User::whoIs( $block->mBy );
132 $ulink = $sk->makeKnownLink( $wgLang->getNsText( Namespace::getUser() ). ":{$name}", $name );
133 $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
134
135 if ( $block->mExpiry === "" ) {
136 $formattedExpiry = "indefinite";
137 } else {
138 $formattedExpiry = $wgLang->timeanddate( $block->mExpiry, true );
139 }
140
141 $line = wfMsg( "blocklistline", $formattedTime, $ulink, $addr, $formattedExpiry );
142
143 $wgOut->addHTML( "<li>{$line}" );
144
145 if ( !$block->mAuto ) {
146 $titleObj = Title::makeTitle( NS_SPECIAL, "Contributions" );
147 $clink = "<a href=\"" . $titleObj->escapeLocalURL( "target={$block->mAddress}" ) . "\">" .
148 wfMsg( "contribslink" ) . "</a>";
149 $wgOut->addHTML( " ({$clink})" );
150 }
151
152 if ( $wgUser->isSysop() ) {
153 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
154 $ublink = "<a href=\"" .
155 $titleObj->escapeLocalURL( "action=unblock&ip=" . urlencode( $addr ) ) . "\">" .
156 wfMsg( "unblocklink" ) . "</a>";
157 $wgOut->addHTML( " ({$ublink})" );
158 }
159 if ( "" != $block->mReason ) {
160 $wgOut->addHTML( " <em>(" . htmlspecialchars( $block->mReason ) .
161 ")</em>" );
162 }
163 $wgOut->addHTML( "</li>\n" );
164 }
165
166
167 ?>